<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>后台广告管理</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" href="favicon.ico">
    <link href="/Public/Admin/css/bootstrap.min.css" rel="stylesheet">
    <link href="/Public/Admin/css/font-awesome.min.css" rel="stylesheet">
    <link href="/Public/Admin/css/animate.css" rel="stylesheet">
    <link href="/Public/Admin/css/style.css" rel="stylesheet">
    <link href="/Public/Admin/js/plugins/layer/skin/default/layer.css" rel="stylesheet">
    <link rel="stylesheet" href="/Public/Admin/css/plugins/switchery/switchery.css" />
    <link href="/Public/Admin/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
</head>
<body>
<div class="col-sm-12">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>广告管理</h5>
            <div class="ibox-tools">
            </div>
        </div>
        <div class="ibox-content">
                <div class="row m-b-sm m-t-sm">
                    <div class="col-md-2">
                        <a href="javascript:addM();" class="btn btn-outline btn-primary">添加广告版块</a>
                    </div>
                </div>
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>版块名称</th>
                    <th>版块类型</th>
                    <th>版块尺寸</th>
                    <th>广告数</th>
                    <th>版块描述</th>
                    <th>管理操作</th>
                </tr>
                </thead>
                <tbody id="tbody">
                    <?php if(is_array($list)): $i = 0; $__LIST__ = $list;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><tr>
                            <td><?php echo ($vo["id"]); ?></td>
                            <td><?php echo ($vo["name"]); ?></td>
                            <td><?php if($vo["type"] == 'banner' ): ?>图片广告
                                    <?php else: ?> 代码广告<?php endif; ?></td>
                            <td><?php echo ($vo["width"]); ?>&nbsp; * &nbsp;<?php echo ($vo["height"]); ?></td>
                            <td><?php echo ($vo["items"]); ?></td>
                            <td><?php echo ($vo["description"]); ?></td>
                            <td>
                                <a href="<?php echo U('poster/index?id='.$vo['id']);?>" type="button" class="btn btn-outline btn-info"><i class="fa fa-pencil-square-o"></i>广告列表</a>
                                <a href="javascript:editspace(<?php echo ($vo["id"]); ?>);" type="button" class="btn btn-outline btn-info"><i class="fa fa-pencil-square-o"></i>修改</a>
                                <a href="javascript:Delspace(<?php echo ($vo["id"]); ?>)" class="btn btn-outline btn-danger"><i class="fa fa-trash-o"></i>删除</a>
                                <a href="<?php echo U('poster/add?id='.$vo['id']);?>" type="button" class="btn btn-outline btn-info"><i class="fa fa-pencil-square-o"></i>添加广告</a>
                            </td>
                        </tr><?php endforeach; endif; else: echo "" ;endif; ?>
                </tbody>
            </table>
        </div>
    </div>
</div>

<div class="modal fade form-horizontal" style=" display: none;" id="addM" >
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title" id="myModalLabel">添加版位</h4>
            </div>
            <div class="modal-body" style="height:500px;">
                <form method="post" action="<?php echo U('Posterspace/savespace');?>" id="form" name="form">
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">版位名称</label>

                        <div class="col-sm-7">
                            <input type="text" name="title" id="title" placeholder="请输入版位名称" class="form-control">
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">版位类型</label>

                        <div class="col-sm-8">
                            <select class="form-control m-b" name="type" id="type">
                                <option value="banner">图片广告</option>
                                <option value="text">代码广告</option>
                            </select>
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">版位尺寸:</label>

                        <div class="col-sm-4">
                            <input type="text" value="" name="width" id="width" placeholder="请输入版位宽度" class="form-control">
                        </div>
                        <div class="col-sm-4">
                            <input type="text" value="" name="height" id="height" placeholder="请输入版位高度" class="form-control">
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">版位描述</label>
                        <div class="col-sm-10">
                            <textarea name="description" id="description" class="form-control" rows="4"></textarea>
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class=" col-sm-offset-2">
                        <button id="submit" class="btn btn-primary" type="submit">保存内容</button>
                    </div>
                </form>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->

</div>

<script src="/Public/Admin/js/jquery.min.js"></script>
<script src="/Public/Admin/js/bootstrap.min.js"></script>
<script src="/Public/Admin/js/plugins/layer/layer.js"></script>
<script src="/Public/Admin/js/plugins/layer/laypage/laypage.js"></script>
<script src="/Public/Admin/js/plugins/switchery/switchery.js"></script>
<script src="/Public/Admin/js/plugins/sweetalert/sweetalert.min.js"></script>
<script src="/Public/Admin/js/comment.js"></script>
</body>
<script>
    var eid = 0;
    function addM(){
        $('#title').val('');
        $('#type').val('');
        $('#width').val('');
        $('#height').val('');
        $('#description').val('');
        $('#addM').modal({ });
    }
    $('#submit').click(function (){
        var title = $('#title').val();
        if(title == ''){
            layer.tips('版块名称不能为空', '#title', {
                tips: 2
            });
            return false;
        }
        var type = $('#type').val();
        if(type == ''){
            layer.tips('版块类型不能为空', '#type', {
                tips: 2
            });
            return false;
        }
        var objNames = $('#form').serializeArray();
        var dataNames = new Object();
        $.each(objNames,function(key,val){
            dataNames[val.name] = val.value;
        });
        dataNames['id'] = eid;
        $.post($('#form').prop('action'),dataNames,function(data){
            if(data.status > 0){
                $('#addM').modal('hide');
                swal({title: "OMG",text: data.msg,type: "error"}, function() { window.location.reload();
                });
            }else{
                $('#addM').modal('hide');
                swal({title: "Good",text: data.msg,type: "success"}, function() { window.location.reload();
                });
            }
        },'json');
        return false;
    });
    function editspace(id){
        $.post("<?php echo U('Posterspace/getMenu');?>",{id:id},function(data) {
            if(data.status > 0){
                swal({title: "OMG",text: data.msg,type: "error"});
            }
            eid = data.data[0]['id'];
            $('#title').val(data.data[0]['name']);
            $('#type').val(data.data[0]['type']);
            $('#width').val(data.data[0]['width']);
            $('#height').val(data.data[0]['height']);
            $('#description').val(data.data[0]['description']);
            $('#addM').modal({ });
        },'json')
    }
    function Delspace(id){
        swal({
            title: "您确定要删除吗？",
            text: "",
            type: "warning",
            showCancelButton: true,
            closeOnConfirm: false,
            confirmButtonText: "删除",
            confirmButtonColor: "#ec6c62",
            cancelButtonText: "取消"
        }, function() {
            $.post("<?php echo U('Posterspace/del');?>",{id:id},function(data){
                if(data.status > 0){
                    swal({title: "OMG",text: data.msg,type: "error"}, function() { window.location.reload();
                    });
                }else{
                    swal({title: "Good",text: data.msg,type: "success"}, function() { window.location.reload();
                    })
                }
            });
        })
    }
</script>
</html>